<template>
    <div style="height:100%">
      <div>
        <div class='content-title'>
          <div class='content-title-parent'>失物管理</div>
          /
          <div class='content-title-child'>失物招领</div>
        </div>
        <hr class='content-hr'/>
      </div>
      <!--表格筛选条件-->
      <el-row style="margin-top:10px" class='lostManaClass'>
        <el-form v-model="filterForm" ref="filterForm" :inline="true">
          <el-form-item label="物品关键字：" label-width="100px">
            <el-input style="width:160px" @keyup.native="filterForm.materialName=filterForm.materialName.replace(/[^\w\u4e00-\u9fa5\s]/g, '')" clearable v-model.trim="filterForm.materialName"></el-input>
          </el-form-item>
          <el-form-item label="物品分类：">
            <el-select style="width:160px" v-model="filterForm.classId" clearable placeholder="选择物品分类">
              <el-option
                v-for="item in categoryList"
                :key="item.classId"
                :label="item.className"
                :value="item.classId">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="遗失地点：">
              <el-cascader
                clearable
                style="width:160px"
                v-model="filterForm.airportList"
                expand-trigger="hover"
                :options="filterForm.airportNameList"
                @change="selectAirport('filterForm')"
                :props="airportProps"
              >
              </el-cascader>
          </el-form-item>
          <el-form-item label="登记日期：" label-width="100px">
            <el-date-picker
              v-model="filterForm.lostTime"
              type="daterange"
              align="right"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="物品状态：" >
            <el-checkbox-group v-model="filterForm.goodsState">
              <el-checkbox label="待领取"></el-checkbox>
              <el-checkbox label="已领取"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="" >
            <el-button type="primary" style="background-color:#2280E9;border-color:#2280E9;width:60px;" @click="submitSearch()">查询</el-button>
          </el-form-item>
          <el-form-item label="" style="float:right;margin-right:20px">
            <el-button type="warning" style="width:80px;" @click="addVisable = true">添加失物</el-button>
          </el-form-item>
        </el-form>
      </el-row>
      <!--查询表格数据-->
      <el-row>
        <el-table 
          class='lostManaTableClass'
          v-loading="loading"
          :element-loading-text="loadingText"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(255, 255, 255, 0.8)"
          :data="filterFormFro.tableData"
          :border="true"
          :cell-class-name="tabelCellClassName"
          :row-class-name="tableRowClassName"
          :header-cell-class-name = "tableHeaderClassName"
          v-bind:style="{width: tableWidth + 'px'}">
            <el-table-column prop="index" label="序号"  min-width="5%">
            </el-table-column>
            <el-table-column prop="materialName" label="物品名称" min-width="10%">
            </el-table-column>
            <el-table-column prop="className" label="物品分类" min-width="7%">
            </el-table-column>
            <el-table-column prop="codeAirport" label="所属机场" min-width="10%">
            </el-table-column>
            <el-table-column prop="terminalName" label="遗失地点"  min-width="10%">
            </el-table-column>
            <el-table-column prop="address" label="详细地址"  min-width="10%">
            </el-table-column>
            <el-table-column prop="registerTime" label="登记日期" min-width="10%">
            </el-table-column>
            <el-table-column prop="goodsState" label="状态" min-width="7%">
            </el-table-column>
            <el-table-column label="操作" width="200" fixed="right">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="primary"
                @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <!--分页-->
      <el-row>
        <div class="pagination" style="text-align:center" v-show="paginationVisible">
          <el-pagination
            @current-change="handleCurrentChange"
            background
            :current-page="filterForm.pageNum"
            :page-size="15"
            layout="total, prev, pager, next"
            :page-count="filterFormFro.totalPage">
          </el-pagination>
        </div>
      </el-row>              
      <!-- 添加失物信息信息弹窗 -->
      <el-dialog title="添加失物:"   :visible.sync="addVisable"
          :closeOnClickModal="false" 
          width="550px"
          class="categoryManaDialog"
          :close-on-click-modal="false" 
          :close-on-press-escape="false"
          @close="resetForm('addForm')">
        <el-form :model='addForm' ref="addForm" :rules="addRules" label-width="155px">
            <el-form-item label="物品名称："  prop="materialName">
              <el-input style='width:240px' @keyup.native="addForm.materialName=addForm.materialName.replace(/[^\w\u4e00-\u9fa5\s]/g, '')" v-model.trim="addForm.materialName"></el-input>
            </el-form-item>
            <el-form-item label="物品分类："  prop="classId">
              <el-select style='width:240px' v-model="addForm.classId" clearable placeholder="选择物品分类">
                <el-option
                  v-for="item in categoryList"
                  :key="item.classId"
                  :label="item.className"
                  :value="item.classId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="遗失地点：" prop="airportList">
              <el-cascader
                style='width:240px'
                v-model="addForm.airportList"
                expand-trigger="hover"
                :options="addForm.airportNameList"
                @change="selectAirport('addForm')"
                :props="airportProps"
              >
              </el-cascader>
            </el-form-item>
            <el-form-item label="详细地址："  prop="address">
              <el-input style='width:240px' @keyup.native="addForm.address=addForm.address.replace(/[^\w\u4e00-\u9fa5\s]/g, '')"  v-model.trim="addForm.address" ></el-input>
            </el-form-item>
            <el-form-item label="登记时间："  prop="registerTime">
                <el-date-picker
                  style='width:240px'
                  clearable
                  v-model="addForm.registerTime"
                  type="date"
                  :picker-options="pickerOptions0"
                  placeholder="选择日期">
                </el-date-picker>
            </el-form-item>
            <!-- <el-form-item label="领取地点：" prop="pickairportList">
              <el-cascader
                clearable
                style='width:240px'
                v-model="addForm2.airportList"
                expand-trigger="hover"
                :options="addForm2.airportNameList"
                @change="selectAirport('addForm2')"
                :props="airportProps"
              >
              </el-cascader>
            </el-form-item> -->
            <el-form-item label="领取地点："  prop="placeId">
              <el-select style='width:240px' v-model="addForm.placeId" placeholder="选择领取地点">
                <el-option
                  v-for="item in pickUpList"
                  :key="item.placeId"
                  :label="item.placeName"
                  :value="item.placeId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="物品状态："  prop="goodsState">
              <el-radio-group style='width:240px' v-model="addForm.goodsState">
                <el-radio label="待领取">待领取</el-radio>
                <el-radio label="已领取">已领取</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="" >
              <el-button type="primary" style="width:240px" @click="submitAdd()">保 存</el-button>
            </el-form-item>
        </el-form>
      </el-dialog>
      <!-- 编辑失物信息信息弹窗 -->
      <el-dialog title="编辑失物信息:"   :visible.sync="editVisable"
          :closeOnClickModal="false" 
          width="550px"
          class="categoryManaDialog"
          :close-on-click-modal="false" 
          :close-on-press-escape="false"
          @close="resetForm('editForm')">
        <el-form :model='editForm' :rules="editRules" ref="editForm" label-width="165px">
            <el-form-item label="物品名称：" prop="materialName">
              <el-input style='width:240px' @keyup.native="editForm.materialName=editForm.materialName.replace(/[^\w\u4e00-\u9fa5\s]/g, '')"   clearable v-model.trim="editForm.materialName"></el-input>
            </el-form-item>
            <el-form-item label="物品分类："  prop="classId">
              <el-select style='width:240px' v-model="editForm.classId" placeholder="选择物品分类">
                <el-option
                  v-for="item in categoryList"
                  :key="item.classId"
                  :label="item.className"
                  :value="item.classId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="遗失地点：" prop="airportList">
              <el-cascader
                style='width:240px'
                v-model="editForm.airportList"
                expand-trigger="hover"
                :options="editForm.airportNameList"
                @change="selectAirport('editForm')"
                :props="airportProps"
              >
              </el-cascader>
            </el-form-item>
            <el-form-item label="详细地址：" prop="address">
              <el-input style='width:240px' @keyup.native="editForm.address=editForm.address.replace(/[^\w\u4e00-\u9fa5\s]/g, '')" clearable v-model.trim="editForm.address"></el-input>
            </el-form-item>
            <el-form-item label="登记时间："  prop="registerTime">
                <el-date-picker
                  style='width:240px'
                  v-model="editForm.registerTime"
                  type="datetime"
                  placeholder="选择日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="领取地点："  prop="placeId">
              <el-select style='width:240px' v-model="editForm.placeId" placeholder="选择领取地点">
                <el-option
                  v-for="item in pickUpList"
                  :key="item.placeId"
                  :label="item.placeName"
                  :value="item.placeId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="物品状态："  prop="goodsState">
              <el-radio-group style='width:240px' v-model="editForm.goodsState">
                <el-radio label="待领取">待领取</el-radio>
                <el-radio label="已领取">已领取</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="" >
              <el-button type="primary" style="width:240px" @click="submitEdit()">保 存</el-button>
            </el-form-item>
        </el-form>
      </el-dialog>
    </div>
</template>
<script>
import apiBus from '../../api/businessPlat/apiBus.js'
import '../../../static/css/businessPlat/common.css'
import '../../../static/css/businessPlat/lostMana.css'
export default {
  created () {
    this.init()
    this.getAllClassFro()
    this.getAllTerminalFro()
    this.getLostManaListFro()
    this.getPickUpListFro() // 查询所有失物领取地点
  },
  data () {
    return {
      addVisable: false, // 添加失物弹窗
      baseFeeVisable: true,
      loading: false, // 加载是否显示
      loadingText: '', // 加载显示内容
      categoryList: [], // 下拉框中的失物分类列表
      pickUpList: [], // 失物领取地点列表
      tableWidth: '', // 表格宽度
      pickerOptions0: {
        disabledDate (time) {
          return time.getTime() > Date.now() - 8.64e6
        }
      },
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      airportProps: {
        value: 'label',
        children: 'terminals'
      },
      props: {
        value: 'label',
        children: 'cities'
      },
      filterFormFro: { // 查询获得列表
        tableData: [],
        totalPage: 0
      },
      filterForm: { // 筛选表单
        materialName: '', // 失物名称
        className: '',
        classId: '',
        terminalId: [],
        terminalName: [],
        airportName: '',
        airportId: '',
        flightNumber: '',
        lostTime: [],
        pageNum: 1,
        isDelete: '',
        airportNameList: [],
        airportList: [],
        goodsState: ['待领取', '已领取'], // 物品状态
        statusList: ['未找到', '已找到']
      },
      testAirport: [
        {
          airportName: '机场1',
          airportId: '机场1',
          terminalName: '航站楼11',
          terminalId: '航站楼ID'
        },
        {
          airportName: '机场2',
          airportId: '机场ID',
          terminalName: '航站楼21',
          terminalId: '航站楼ID'
        },
        {
          airportName: '机场1',
          airportId: '机场1',
          terminalName: '航站楼12',
          terminalId: '航站楼ID'
        }
      ],
      paginationVisible: false, // 表格下方分页是否显示
      noteVisible: false,
      formLabelWidth: '30%',
      addForm: {
        airportNameList: [],
        materialName: '',
        classId: '',
        airportList: [],
        terminalId: [],
        terminalName: [],
        airportId: '',
        airportName: '',
        address: '',
        registerTime: '',
        goodsState: ''
      },
      addForm2: {
        airportNameList: [],
        airportList: [],
        airportId: '',
        airportName: '',
        terminalId: [],
        terminalName: []
      },
      editForm: {
        index: 0,
        airportNameList: [],
        materialName: '',
        classId: '',
        placeId: '',
        airportList: [],
        terminalId: [],
        terminalName: [],
        airportId: '',
        airportName: '',
        address: '',
        registerTime: '',
        goodsState: ''
      },
      editForm2: {
        airportNameList: [],
        airportList: [],
        airportId: '',
        airportName: '',
        terminalId: [],
        terminalName: []
      },
      editVisable: false,
      deleteForm: { // 删除表单
        index: '',
        materialId: ''
      },
      addRules: { // 弹窗添加失物信息验证规则
        materialName: [
          { required: true, message: '请填写物品名称', trigger: 'blur' },
          { max: 20, message: '物品名称最多20个字', trigger: 'blur' }
        ],
        classId: [
          { required: true, message: '请选择所属分类', trigger: 'change' }
        ],
        airportList: [
          { required: true, message: '请选择遗失地点', trigger: 'change' }
        ],
        address: [
          { required: true, message: '请填写详细地址', trigger: 'blur' },
          { max: 30, message: '详细地址最多30个字', trigger: 'blur' }
        ],
        registerTime: [
          { required: true, message: '请填写遗失时间', trigger: 'blur' }
        ],
        placeId: [
          { required: true, message: '请选择领取地点', trigger: 'change' }
        ],
        goodsState: [
          { required: true, message: '请选择物品状态', trigger: 'change' }
        ]
      },
      editRules: { // 弹窗编辑失物信息验证规则
        materialName: [
          { required: true, message: '请填写物品名称', trigger: 'blur' },
          { max: 20, message: '物品名称最多20个字', trigger: 'blur' }
        ],
        classId: [
          { required: true, message: '请选择所属分类', trigger: 'change' }
        ],
        airportList: [
          { required: true, message: '请选择遗失地点', trigger: 'change' }
        ],
        address: [
          { required: true, message: '请填写详细地址', trigger: 'blur' },
          { max: 30, message: '详细地址最多30个字', trigger: 'blur' }
        ],
        registerTime: [
          { required: true, message: '请填写遗失时间', trigger: 'blur' }
        ],
        placeId: [
          { required: true, message: '请选择领取地点', trigger: 'blur' }
        ],
        goodsState: [
          { required: true, message: '请选择物品状态', trigger: 'change' }
        ]
      }
    }
  },
  methods: {
    /** 页面处理，数据格式处理函数 */
    submitSearch () {
      this.filterForm.pageNum = 1
      this.getLostManaListFro()
    },
    // 分页页面跳转时
    handleCurrentChange (val) {
      this.filterForm.pageNum = val
      this.getLostManaList()
    },
    // 处理后台发来的数据以显示在下拉框中（主要针对机场和航站楼，使其可以二级联动选择）
    setDropdown (testAirport, form) {
      let parentIdList = []
      let totalList = []
      for (let i = 0; i < testAirport.length; i++) {
        if (parentIdList.indexOf(testAirport[i].airportId) === -1) {
          parentIdList.push(testAirport[i].airportId)
          totalList.push({
            label: testAirport[i].figureThree + ' ' + testAirport[i].airportName,
            airportId: testAirport[i].airportId,
            terminals: []
          })
        }
      }
      for (let i = 0; i < totalList.length; i++) {
        testAirport.forEach((item) => {
          if (item.airportId === totalList[i].airportId) {
            totalList[i].terminals.push({
              label: item.terminalName,
              terminalId: item.terminalId
            })
          }
        })
      }
      if (form === 'filterForm') {
        for (let i = 0; i < totalList.length; i++) {
          totalList[i].terminals.push({
            label: '全部',
            terminalId: ''
          })
        }
      }
      this[form].airportNameList = totalList
    },
    // 将时间从时间戳转化为字符串显示
    formatDateFro (now) {
      var year = now.getFullYear()
      var month = now.getMonth() + 1
      month = month < 10 ? '0' + month : month
      var date = now.getDate()
      date = date < 10 ? ('0' + date) : date
      var hour = now.getHours()
      hour = hour < 10 ? ('0' + hour) : hour
      var minute = now.getMinutes()
      minute = minute < 10 ? ('0' + minute) : minute
      var second = now.getSeconds()
      second = second < 10 ? ('0' + second) : second
      return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second
    },
    // 将时间从时间戳转化为字符串显示（只有日期）
    formatDateShortFro (now) {
      var year = now.getFullYear()
      var month = now.getMonth() + 1
      month = month < 10 ? '0' + month : month
      var date = now.getDate()
      date = date < 10 ? ('0' + date) : date
      return year + '-' + month + '-' + date
    },
    // 将时间转化为字符串(filterForm)
    formatDayFro (now) {
      var year = now.getFullYear()
      var month = now.getMonth() + 1
      month = month < 10 ? '0' + month : month
      var date = now.getDate() + 1
      date = date < 10 ? ('0' + date) : date
      var hour = now.getHours()
      hour = hour < 10 ? ('0' + hour) : hour
      var minute = now.getMinutes()
      minute = minute < 10 ? ('0' + minute) : minute
      var second = now.getSeconds()
      second = second < 10 ? ('0' + second) : second
      return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second
    },
    // 下拉框选择机场及航站楼
    selectAirport (Form) {
      for (let i = 0; i < this[Form].airportNameList.length; i++) {
        this[Form].terminalId = []
        if (this[Form].airportNameList[i].label === this[Form].airportList[0]) {
          this[Form].airportId = this[Form].airportNameList[i].airportId
          this[Form].airportName = this[Form].airportNameList[i].label
          for (let m = 0; m < this[Form].airportNameList[i].terminals.length; m++) {
            if (this[Form].airportList[1] === this[Form].airportNameList[i].terminals[m].label && this[Form].airportList[1] !== '全部') {
              this[Form].terminalId.push(this[Form].airportNameList[i].terminals[m].terminalId)
              this[Form].terminalName.push(this[Form].airportNameList[i].terminals[m].label)
              break
            } else if (this[Form].airportList[1] === '全部') {
              if (this[Form].airportNameList[i].terminals[m].label !== '全部') {
                this[Form].terminalId.push(this[Form].airportNameList[i].terminals[m].terminalId)
                this[Form].terminalName.push(this[Form].airportNameList[i].terminals[m].label)
              }
            }
          }
          break
        }
      }
    },
    setDetailFro () {
      this.editVisable = false
      this.$message.success('失物详情编辑成功')
    },
    // 增加标签，点击“保存”
    submitAdd () {
      this.$refs['addForm'].validate((valid) => {
        if (valid) {
          this.addLostManaFro()
        } else {
          return false
        }
      })
    },
    // 编辑标签，点击“保存”
    submitEdit () {
      this.$refs['editForm'].validate((valid) => {
        if (valid) {
          this.editLostManaFro()
        } else {
          return false
        }
      })
    },
    // 重置表单
    resetForm (formName) {
      this.$nextTick(function () {
        this.$refs[formName].resetFields()
        this.addForm2.airportList = []
      })
    },
    // 初始化搜索数据
    init () {
      /* let end = new Date()
      let start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      this.filterForm.lostTime[0] = start
      this.filterForm.lostTime[1] = end */
      let end = new Date()
      let start = new Date()
      let hour = new Date().getHours()
      let minute = new Date().getMinutes()
      let second = new Date().getSeconds()
      start.setTime(start.getTime() - hour * 3600 * 1000 - minute * 60 * 1000 - second * 1000 - 24 * 3600 * 30 * 1000)
      end.setTime(end.getTime() - hour * 3600 * 1000 - minute * 60 * 1000 - second * 1000)
      this.filterForm.lostTime[0] = start
      this.filterForm.lostTime[1] = end
    },
    tableHeaderClassName ({row, column, rowIndex, columnIndex}) {
      if (rowIndex === 0) {
        return 'headerClass'
      }
    },
    tableRowClassName ({row, rowIndex}) {
      return 'rowClass'
    },
    tabelCellClassName ({row, column, rowIndex, columnIndex}) {
      if (columnIndex === 7) {
        if (row.goodsState === '待领取') {
          return 'cellClass'
        } else {
          return 'cellClassNo'
        }
      }
    },
    // 点击表格中的编辑按钮
    handleEdit (index, row) {
      let data = this.filterFormFro.tableData[index]
      this.editForm.materialName = data.materialName.trim()
      this.editForm.materialId = data.materialId
      this.editForm.classId = data.classId
      this.editForm.airportName = data.airportName
      this.editForm.terminalName[0] = data.terminalName
      this.editForm.airportList[0] = data.figureThree + ' ' + data.airportName
      this.editForm.airportList[1] = data.terminalName
      this.editForm.address = data.address.trim()
      this.editForm.registerTime = data.registerTime
      this.editForm.goodsState = data.receiveState
      this.editForm.placeId = data.placeId
      this.editVisable = true
    },
    // 点击表格中的删除按钮
    handleDelete (index, row) {
      let data = this.filterFormFro.tableData[index]
      this.deleteForm.materialId = data.materialId
      this.$confirm('确认删除该失物吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteLostManaFro()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    cancleEdit (formName) {
      this.resetError(formName)
      this.editVisable = false
    },
    // 重置表单
    resetError (formName) {
      this.$nextTick(function () {
        this.$refs[formName].resetFields()
      })
    },
    setDeleteFro () {
      this.noteVisible = false
      this.$message.success('优惠券<' + this.deleteForm.couponName + '>已删除')
    },
    // 从后台查询所有航站楼
    getAllTerminalFro () {
      let para = {
        header: JSON.stringify({
          token: sessionStorage.getItem('token'),
          beanId: 'airportService_v1'
        }),
        body: JSON.stringify({})
      }
      apiBus.getAllTerminal(para).then(res => {
        let terminalList = []
        if (res.data.body.result === 1000) {
          terminalList = res.data.body.content.list
          this.setDropdown(terminalList, 'filterForm')
          this.setDropdown(terminalList, 'addForm')
          this.setDropdown(terminalList, 'editForm')
          this.setDropdown(terminalList, 'addForm2')
          this.setDropdown(terminalList, 'editForm2')
        } else {
          this.$message.error(res.data.body.resultDesp)
        }
      })
      .catch(error => {
        this.$message.error(error)
      })
    },
    // 查询电商标签管理处的电商分类下拉菜单的显示接口
    getAllClassFro () {
      let para = {
        header: JSON.stringify({
          'token': sessionStorage.getItem('token'),
          'beanId': 'lostMeterialService_v1'
        }),
        body: JSON.stringify({})
      }
      apiBus.getLostCategoryList(para).then(res => {
        this.categoryList = []
        if (res.data.body.result === 1000) {
          this.categoryList = res.data.body.content.list
        } else {
          this.$message.error(res.data.body.resultDesp)
        }
      })
      .catch(error => {
        this.$message.error(error)
      })
    },
    // 查询所有失物领取地点
    getPickUpListFro () {
      this.pickUpList = []
      let para = {
        header: JSON.stringify({
          'token': sessionStorage.getItem('token')
        }),
        body: JSON.stringify({})
      }
      apiBus.getPickUpList(para).then(res => {
        if (res.data.body.result === 1000) {
          this.pickUpList = res.data.body.content.list
        } else {
          this.$message.error(res.data.body.resultDesp)
        }
      })
      .catch(error => {
        this.$message.error(error)
      })
    },
    /** 向后台发送删除失物信息 */
    deleteLostManaFro () {
      let para = {
        header: JSON.stringify({
          token: sessionStorage.getItem('token'),
          beanId: 'lostMeterialService_v1'
        }),
        body: JSON.stringify({
          materialId: this.deleteForm.materialId
        })
      }
      apiBus.deleteLostMana(para).then(res => {
        if (res.data.body.result === 1000) {
          this.$message.success('成功删除失物信息！')
          this.editVisable = false
          this.filterForm.pageNum = 1
          this.getLostManaListFro()
        } else {
          this.$message.error(res.data.body.resultDesp)
        }
      })
      .catch(error => {
        this.$message.error(error)
      })
    },
    /** 向后台发送编辑失物信息 */
    editLostManaFro () {
      let terminalId = ''
      // let pickUpTerminalId = ''
      let registerTime = ''
      this.editForm.registerTime ? registerTime = this.formatDateFro(new Date(this.editForm.registerTime)) : ''
      this.editForm.terminalId.length > 1 ? terminalId = '' : terminalId = parseInt(this.editForm.terminalId[0])
      // this.editForm2.terminalId.length > 1 ? pickUpTerminalId = '' : pickUpTerminalId = parseInt(this.editForm2.terminalId[0])
      terminalId = 1
      let para = {
        header: JSON.stringify({
          token: sessionStorage.getItem('token'),
          beanId: 'lostMeterialService_v1'
        }),
        body: JSON.stringify({
          materialName: this.editForm.materialName,
          classId: parseInt(this.editForm.classId),
          // airportId: parseInt(this.editForm.airportId),
          airportId: 1,
          materialId: parseInt(this.editForm.materialId),
          terminalId: terminalId,
          placeId: parseInt(this.editForm.placeId),
          address: this.editForm.address,
          // pickUpTerminalId: pickUpTerminalId,
          // pickUpAirportId: parseInt(this.editForm2.airportId),
          registerTime: registerTime,
          receiveState: this.editForm.goodsState
        })
      }
      apiBus.editLostMana(para).then(res => {
        if (res.data.body.result === 1000) {
          this.$message.success('成功编辑失物信息！')
          this.editVisable = false
          this.filterForm.pageNum = 1
          this.getLostManaListFro()
        } else {
          this.$message.error(res.data.body.resultDesp)
        }
      })
      .catch(error => {
        this.$message.error(error)
      })
    },
    /** 向后台发送增加失物信息 */
    addLostManaFro () {
      let terminalId = ''
      // let pickUpTerminalId = ''
      let registerTime = ''
      this.addForm.registerTime ? registerTime = this.formatDateFro(this.addForm.registerTime) : ''
      this.addForm.terminalId.length > 1 ? terminalId = '' : terminalId = parseInt(this.addForm.terminalId[0])
      // this.addForm2.terminalId.length > 1 ? pickUpTerminalId = '' : pickUpTerminalId = parseInt(this.addForm2.terminalId[0])
      terminalId = 1
      let para = {
        header: JSON.stringify({
          token: sessionStorage.getItem('token'),
          beanId: 'lostMeterialService_v1'
        }),
        body: JSON.stringify({
          materialName: this.addForm.materialName,
          classId: parseInt(this.addForm.classId),
          // airportId: parseInt(this.addForm.airportId),
          airportId: parseInt(this.addForm.airportId),
          terminalId: terminalId,
          address: this.addForm.address,
          placeId: parseInt(this.addForm.placeId),
          registerTime: registerTime,
          receiveState: this.addForm.goodsState
        })
      }
      apiBus.addLostMana(para).then(res => {
        if (res.data.body.result === 1000) {
          this.$message.success('成功添加失物信息！')
          this.addVisable = false
          this.filterForm.pageNum = 1
          this.getLostManaListFro()
        } else {
          this.$message.error(res.data.body.resultDesp)
        }
      })
      .catch(error => {
        this.$message.error(error)
      })
    },
    /** 向后台发送请求失物列表接口 */
    getLostManaListFro () {
      this.filterFormFro.tableData = []
      this.loading = true
      this.loadingText = '正在拼命加载，请稍等...'
      let terminalId = ''
      let endTime = null
      let startTime = null
      let goodsState = ''
      if (this.filterForm.lostTime && this.filterForm.lostTime.length > 0) {
        endTime = this.formatDayFro(this.filterForm.lostTime[1])
        startTime = this.formatDateFro(this.filterForm.lostTime[0])
      }
      this.filterForm.terminalId.length > 1 ? terminalId = '' : terminalId = parseInt(this.filterForm.terminalId[0])
      this.filterForm.goodsState.length > 0 ? goodsState = this.filterForm.goodsState : goodsState = null
      let para = {
        header: JSON.stringify({
          token: sessionStorage.getItem('token'),
          beanId: 'lostMeterialService_v1'
        }),
        body: JSON.stringify({
          materialName: this.filterForm.materialName,
          classId: parseInt(this.filterForm.classId),
          airportId: parseInt(this.filterForm.airportId),
          terminalId: terminalId,
          startTime: startTime,
          endTime: endTime,
          pageNum: parseInt(this.filterForm.pageNum),
          receiveStates: goodsState
        })
      }
      apiBus.getLostManaList(para).then(res => {
        this.loading = false
        if (res.data.body.result === 1000) {
          if (res.data.body.content.list.length > 0) {
            this.$message.success('成功提取失物管理信息！')
            let resData = res.data.body.content.list
            this.filterFormFro.tableData = resData
            for (let i = 0; i < resData.length; i++) {
              this.filterFormFro.tableData[i].index = (parseInt(this.filterForm.pageNum) - 1) * 15 + i + 1
              this.filterFormFro.tableData[i].goodsState = resData[i].receiveState
              this.filterFormFro.tableData[i].registerTime = this.formatDateShortFro(new Date(this.filterFormFro.tableData[i].registerTime))
              if (this.filterFormFro.tableData[i].figureThree) {
                this.filterFormFro.tableData[i].codeAirport = resData[i].figureThree + ' ' + resData[i].airportName
              } else {
                this.filterFormFro.tableData[i].codeAirport = resData[i].tetradCode + ' ' + resData[i].airportName
              }
            }
            this.filterFormFro.totalPage = res.data.body.content.allPages
            this.filterFormFro.totalPage > 1 ? this.paginationVisible = true : this.paginationVisible = false
          } else {
            this.$message.warning('没有相关失物信息')
            this.paginationVisible = false
          }
        } else {
          this.$message.error(res.data.body.resultDesp)
          this.paginationVisible = false
        }
      })
      .catch(error => {
        this.loading = false
        this.$message.error(error)
      })
    }
  },
  mounted () {
    this.tableWidth = document.body.scrollWidth - 259 - 20
  }
}
</script>